package com.ssm.util;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class MessageUtil {

    public static Map<String, Object> getSuccessMessage(String message, Object obj) {
        Map<String, Object> result = new HashMap<>();
        result.put("status", true);
        result.put("message", message);
        result.put("other", obj);
        return result;
    }

    public static Map<String, Object> getErrorMessage(String message, Object obj) {
        Map<String, Object> result = new HashMap<>();
        result.put("status", false);
        result.put("message", message);
        result.put("other", obj);
        return result;
    }

    public static boolean isAjax(HttpServletRequest request) {
        return "XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With")) || request.getParameter("ajax") != null;
    }
}
